import { useState } from 'react';
import store from '../redux/store'
import '../assets/css/PersonInfo.css'
import { useNavigate } from 'react-router-dom';
import { removeToken } from '../redux/action';
function PersonInfo() {
    const [info, setInfo] = useState('')
    let navigate = useNavigate()
    let flag = store.getState().IdentityMode.title == '老板列表'
    const url = flag ? 'http://127.0.0.1:8080/dashen/dashenInfo' : 'http://127.0.0.1:8080/laoban/laobanInfo'
    fetch(url, {
        headers: {
            'token': store.getState().TokenMode.token
        }
    }).then(res => res.json()).then(res => {
        if (info == '') {
            setInfo(res.data)
        }
    })
    return (
        <div>
            <div className="">
                <div className="head">
                    <img className='personAvatar' src={info.avatar} alt="" width="20%" />
                    <p className='personName'>{flag ? info.dashenName : info.laobanName}</p>
                </div>
                <p className='personTitle'>相关信息</p>
                <div className="message">
                    {flag ? laobanMsg() : dashenMsg()}
                </div>
                <div className="personBtn" onClick={() => {
                    store.dispatch(removeToken())
                    navigate('/')
                }}>退出登录</div>
            </div>
        </div>
    )
    function dashenMsg() {
        return (
            <div>
                <p>职位: {info.job}</p>
                <p>公司: {info.companyName}</p>
                <p>要求: {info.jobRequirements}</p>
                <p>薪资: {info.positionSalary}</p>
            </div>
        )
    }
    function laobanMsg() {
        return (
            <div>
                <p>职位: {info.job}</p>
                <p>简介: {info.personalIntroduction}</p>
            </div>
        )
    }
}

export default PersonInfo